//
//  EvaluateViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/31.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "EvaluateViewController.h"
#import <YYStarView.h>


@interface EvaluateViewController ()

@property (nonatomic, strong) YYStarView *starView;

@property (nonatomic, strong) UILabel *scoreLb;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionview;

@property (weak, nonatomic) IBOutlet UITextView *evaluateTV;

@end

@implementation EvaluateViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {
    
    self.title = @"发表评论";
    
    UIView *headBGView = [[UIView alloc] init];
    headBGView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:headBGView];
    
    [headBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(160);
    }];
    
    YYStarView *starView = [YYStarView new];
    starView.starBrightImageName = @"daxing_sel";
    starView.starDarkImageName = @"daxing_nor";
    starView.starSpacing = 10;
    starView.starScore = 5.0;
    starView.starClick = ^ {
        self.scoreLb.text = [NSString stringWithFormat:@"%.1lf分",self.starView.starScore];
    };
    
    [headBGView addSubview:self.scoreLb];
    [headBGView addSubview:starView];
    
    [self.scoreLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(20);
    }];
    
    [starView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);//无需设置大小size，只需设置位置即可
        make.top.mas_equalTo(self.scoreLb.mas_bottom).offset(20);
    }];
    self.starView = starView;
    self.scoreLb.text = @"5.0分";//启动懒加载
}

- (IBAction)handleAction:(id)sender {
    
    //检查星星数  检查文字    图片等信息
    
    if (self.starView.starScore == 0) {
        return;
    }
    
    
    [self request_evaluate];
}

#pragma mark - Lazy
- (UILabel *)scoreLb {
    if (!_scoreLb) {
        _scoreLb = [UILabel new];
        _scoreLb.textColor = UIColorHex(0xff5012);
        _scoreLb.font = [UIFont boldSystemFontOfSize:30];
    }
    return _scoreLb;
}

#pragma mark 删除订单
- (void)request_evaluate {
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:@(2) forKey:@"ueEvaluateSource"];
    [dic setValue:self.orderId forKey:@"ueOrderId"];
    [dic setValue:@(1) forKey:@"isDel"];
    [dic setValue:@(1) forKey:@"isDel"];

    [dic setValue:@(1) forKey:@"isDel"];
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_DealOrder];
    WEAKSELF
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
             if (code == 10000) {
                 
                 [weakSelf.navigationController popViewControllerAnimated:YES];
                 [SVProgressHUD showSuccessWithStatus:[data valueForKey:@"message"]];
                 [SVProgressHUD dismissWithDelay:1];
                 
             } else {
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }
    } FailedBlock:^(NSError * _Nonnull error) {}];
}

@end
